package com.example.wly.application_3_homework;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.background.R;

public class MainActivity extends AppCompatActivity {

    private TextView textInfo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //找到控件
        Button btnBackground = (Button) findViewById(R.id.btn_background);
        textInfo = (TextView) findViewById(R.id.tv_info);
        btnBackground.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //点击跳转到颜色界面，选取背景色收，从颜色界面返回
                //带颜色数据
                //带回数据的跳转
                Intent intent = new Intent(MainActivity.this, colorActivity.class);
                startActivityForResult(intent, 1);//请求码---1

            }
        });
    }
    //当从颜色界面返回之后，接收数据
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //获取到回传的数据
        //如果没有关键字，key-value数据不存在，getStringExtra()取出的数值就是第二个参数
        int colorValue1 = data.getIntExtra("color", 0);
        //设置文本框的背景色
        textInfo.setBackgroundColor(colorValue1);
    }
}
